# -*- mode: Makefile; -*-
#----------------------------------------------------------------------------
# 
# ****                pl2texi document generation Makefile              *****
# 
# You may not have to change things in this file (most things you want to 
# change are in SETTINGS), but you should probably check just in case.
#----------------------------------------------------------------------------
# gmake			generate documentation files according to SETTINGS
# gmake	install		install documentation in dirs indicated in SETTINGS
# gmake	uninstall	uninstall documentation from dirs indicated in SETTINGS
# gmake clean	 	deletes intermediate files (but leaves targets)
# gmake realclean 	deletes also generated targets (.ps, .dvi, .html, etc.)
# gmake braveclean 	deletes also the .texi files
# 
# gmake xdviview 	makes dvi, calls xdvi 
# gmake psview 		makes ps, calls ghostview
#----------------------------------------------------------------------------
# The trickiness (playing with functions for paths, basenames, etc.) 
# ensures that dependencies are maintained even though the sources and 
# targets may be in diferent directories and the names passed 
# to the application may themselves be different from either source or target
#----------------------------------------------------------------------------
# The two entries below are set to the installation values
# 
LIBDIR=library_directory
PL2TEXI=pl2texi_executable
# ----------------------------------------------------------------------------
# Define this to be the command that runs tex in your system
# 
TEX=tex
# Alternative (sometimes smarter about number of times it needs to run):
# TEX=texi2dvi 
# (but insists on checking the links, which is a pain...)
# ----------------------------------------------------------------------------
# Define this to be the command that runs texindex in your system
# 
# Not needed if texi2dvi is installed
TEXINDEX=texindex
# ----------------------------------------------------------------------------
# Define this to be the command that builds .bbl files from .bib bibliography
# files in your system
# 
BIBTEX=bibtex
# ----------------------------------------------------------------------------
# Define this to be the command that converts dvi to postscript in
# your system
# 
DVIPS=dvips
# ----------------------------------------------------------------------------
# Define this to be the command that converts texinfo files into html
# files in your system.
# While they add support for the @image command, we use a patched version 
# of texi2html 1.52 
# 
TEXI2HTML=$(LIBDIR)/texi2html
# ----------------------------------------------------------------------------
# Define this to be the command that converts texinfo files into info
# files in your system. Set also the appropriate flags.
# 
MAKEINFO=makeinfo
# ----------------------------------------------------------------------------
# Define this to be the command that performs "echo"
# Using printf is best for portability...
# 
ECHO=printf "%b\n" 
# ECHO=echo
#----------------------------------------------------------------------------
# This is a command that updates texinfo node pointers across
# multiple .texi files, and rewrites them as .ltxi files
# 
TEXIUPDATE= emacs -batch -l $(LIBDIR)/emacs-library.el \
                  -f update-all-nodes 
#----------------------------------------------------------------------------
# This is a command that updates the bibligraphic references in .texi files
# 
REFSUPD= emacs -batch -l $(LIBDIR)/emacs-library.el \
                  -f update-all-references
#----------------------------------------------------------------------------
# This is a command that converts .eps files into .gif and .ppm files
# (the -debug option of pstogif does this!)
# 
PSTOGIF= /usr/local/bin/pstogif -debug 
#----------------------------------------------------------------------------
# This is a command that converts .ppm files into .jpg files on stdout
# 
PPMTOJPEG= cjpeg 
#----------------------------------------------------------------------------
#           You should probably not change anything below this 
#----------------------------------------------------------------------------
# Default values in case not defined in SETTINGS (e.g., in older versions)
DATAMODE = 664 # Permissions for automatically generated data files
EXECMODE = 775 # Permissions for automatically generated exec files and dirs
MAINOPTS =     # Options for main file
COMPOPTS =     # Options for component files
#----------------------------------------------------------------------------
include SETTINGS
#----------------------------------------------------------------------------
# Build filenames
VPATH   = $(FILEPATHS) $(SYSTEMPATHS)
COMPTEXI=$(addsuffix .texi,$(basename $(notdir $(COMPONENTS))))
COMPNAMS=$(addsuffix .pl,$(basename $(COMPONENTS)))
BASEMAIN=$(basename $(notdir $(MAIN)))
#----------------------------------------------------------------------------
# Set targets, doit
.PHONY: default
default: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Generating docs ($(DOCFORMATS)) for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	$(MAKE) $(patsubst %,$(BASEMAIN).%,$(DOCFORMATS))
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Done."
	@$(ECHO) "*** --------------------------------------------------------"
#----------------------------------------------------------------------------
# MAIN needs special cases because the process is different

# Eliminated in all targets below dependency on $(PL2TEXI):
# Gives problems in installations (pl2texi may not be accessible)

.PHONY: dvi ps ascii info html
dvi:   $(BASEMAIN).dvi
ps:    $(BASEMAIN).ps
ascii: $(BASEMAIN).ascii
info:  $(BASEMAIN).info
html:  $(BASEMAIN).html

$(BASEMAIN).texi texi: $(MAIN) $(COMPTEXI) $(SETTINGS) 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $(BASEMAIN).pl to $(BASEMAIN).texi ..."
	@$(ECHO) "*** --------------------------------------------------------"
	$(PL2TEXI) $(MAINOPTS) -l $(FILEPATHS) -s $(SYSTEMPATHS) \
	           -i $(INDICES) -main $(notdir $<) $(COMPTEXI)
	-chmod $(DATAMODE) $(BASEMAIN).texi
	-chmod $(DATAMODE) $(BASEMAIN).refs
ifeq (,$(findstring norefs,$(MAINOPTS)))
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Generating $(BASEMAIN)refs.texi, resolving references..."
	@$(ECHO) "*** --------------------------------------------------------"
	-cat *.refs > $*refs.aux
	-@$(ECHO) "\\\bibstyle{$(LIBDIR)/alist}"
	-@$(ECHO) "\\\bibstyle{$(LIBDIR)/alist}"    >> $*refs.aux
	-@$(ECHO) "\\\bibdata{$(BIBFILES)}"
	-@$(ECHO) "\\\bibdata{$(BIBFILES)}"         >> $*refs.aux
	-$(BIBTEX) $*refs
	-mv $*refs.bbl $*refs.el
	-$(REFSUPD) -file $*.texi -refsfile $*refs.el -components $(COMPTEXI) 
	-chmod $(DATAMODE) *.texi
	-cat *.refs > $*refs.aux
	-@$(ECHO) "\\\bibstyle{$(LIBDIR)/pl2texi}"
	-@$(ECHO) "\\\bibstyle{$(LIBDIR)/pl2texi}"  >> $*refs.aux
	-@$(ECHO) "\\\bibdata{$(BIBFILES)}"
	-@$(ECHO) "\\\bibdata{$(BIBFILES)}"         >> $*refs.aux
	-$(BIBTEX) $*refs
	-mv $*refs.bbl $*refs.texi
	-chmod $(DATAMODE) $*refs.aux $*refs.blg 
	-chmod $(DATAMODE) $*refs.texi $*refs.el
endif

$(BASEMAIN).manl manl: $(MAIN) $(SETTINGS)
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $(BASEMAIN).pl to $(BASEMAIN).manl ..."
	@$(ECHO) "*** --------------------------------------------------------"
	$(PL2TEXI) -l $(FILEPATHS) -s $(SYSTEMPATHS) -man $(notdir $<)
	-chmod $(DATAMODE) $(BASEMAIN).manl

$(BASEMAIN).htmlindex htmlindex $(BASEMAIN).htmlbullet htmlbullet: \
	         $(MAIN) $(SETTINGS)
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $(BASEMAIN).pl to $(BASEMAIN).htmlindex ..."
	@$(ECHO) "*** --------------------------------------------------------"
	$(PL2TEXI) $(MAINOPTS) -l $(FILEPATHS) -s $(SYSTEMPATHS) \
                   -htmlindex $(notdir $<)
	-chmod $(DATAMODE) $(BASEMAIN).htmbullet
	-chmod $(DATAMODE) $(BASEMAIN).htmlindex
	$(MAKE) jpgimages

$(BASEMAIN).infoindex infoindex: $(MAIN) $(SETTINGS)
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $(BASEMAIN).pl to $(BASEMAIN).infoindex ..."
	@$(ECHO) "*** --------------------------------------------------------"
	$(PL2TEXI) -l $(FILEPATHS) -s $(SYSTEMPATHS) -infoindex $(notdir $<)
	-chmod $(DATAMODE) $(BASEMAIN).infoindex

jpgimages:
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $(BASEMAIN) image files to .jpg ..."
	@$(ECHO) "*** --------------------------------------------------------"
ifneq (,$(addsuffix .jpg,$(basename $(wildcard $(BASEMAIN)*.eps))))
	$(MAKE) $(addsuffix .jpg,$(basename $(wildcard $(BASEMAIN)*.eps)))
endif

txtimages:
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $(BASEMAIN) image files to .txt ..."
	@$(ECHO) "*** --------------------------------------------------------"
ifneq (,$(addsuffix .txt,$(basename $(wildcard $(BASEMAIN)*.eps))))
	$(MAKE) $(addsuffix .txt,$(basename $(wildcard $(BASEMAIN)*.eps)))
endif

#----------------------------------------------------------------------------
# General cases
.SUFFIXES: .src .pl .texi .ltxi .dvi .ps .html .info .ascii \
           .eps .gif .ppm .jpg .txt

.src.texi: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $*.src (texinfo) to $*.texinfo ..."
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "@c -----------------------------------------" >  $*.texi
	@$(ECHO) "@c Do not edit -- edit the .src file instead" >> $*.texi
	@$(ECHO) "@c -----------------------------------------" >> $*.texi
	cat $*.src >> $*.texi
	-chmod $(DATAMODE) $*.texi

.pl.texi: $(SETTINGS)
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $*.pl to $*.texi ..."
	@$(ECHO) "*** --------------------------------------------------------"
	$(PL2TEXI) $(COMPOPTS) -l $(FILEPATHS) -s $(SYSTEMPATHS) \
                   -i $(INDICES) -component $(filter $*.pl, $(COMPNAMS))
	-chmod $(DATAMODE) $*.texi
	-chmod $(DATAMODE) $*.refs

.texi.dvi: $(SETTINGS)
	@$(ECHO) "*** --------------------------------------------------------"
#	@$(ECHO) "*** Converting $*.texi to $*.dvi (ignore node-type errs)..."
	@$(ECHO) "*** Converting $*.texi to $*.dvi ..."
	@$(ECHO) "*** --------------------------------------------------------"
# Depends on how smart your $(TEX) is...
	-$(TEX) $*.texi
	-$(TEXINDEX) $*.??
	-$(TEX) $*.texi
# Obviously an overkill, but it generates many, many files...
	-chmod $(DATAMODE) $**.*

.dvi.ps: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $*.dvi to $*.ps ..."
	@$(ECHO) "*** --------------------------------------------------------"
	$(DVIPS) -f < $*.dvi > $*.ps
	-chmod $(DATAMODE) $*.ps

.texi.ltxi:
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $*.texi and any components to $*.ltxi ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-$(TEXIUPDATE) -file $*.texi -components $(COMPTEXI)
	-chmod $(DATAMODE) *.ltxi

.ltxi.html:
	$(MAKE) jpgimages
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $*.ltxi to $*.html ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-$(TEXI2HTML) -expandinfo -split_node -glossary -menu $*.ltxi
	-ln -s $*.ltxi_toc.html $*.html
	-chmod $(DATAMODE) *.html

# This is to cancel the internal rule so that the .ltxi one is used!
     %.info : %.texi

# Not in all distributions: --force (only in newer versions of exinfo), 
# but needed: otherwise incomplete info file generated if there are any errors
# As an alternative, set error limit very high... --error-limit 100000
.ltxi.info:
	$(MAKE) txtimages
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $*.ltxi to $*.info ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-$(MAKEINFO) --force --no-split --verbose \
	            --fill-column=70 --output $*.info $*.ltxi
	-chmod $(DATAMODE) $*.info

.texi.ascii:
	$(MAKE) txtimages
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Converting $*.ltxi to $*.ascii ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-$(MAKEINFO) --force --no-validate --no-split --verbose --no-headers \
	            --fill-column=70 --output $*.ascii $*.texi
	-chmod $(DATAMODE) $*.ascii

# The following support the inclusion of images. The source is a .eps file.
# $(PSTOGIF) also generates ppm
.eps.gif:
	@$(ECHO) "Converting $*.eps to $*.gif ..."
	$(PSTOGIF) $*.eps
	-chmod $(DATAMODE) $*.gif
	-rm -f $*.ppm
	-rm -f $*.ppm.tmp

.eps.ppm:
	@$(ECHO) "Converting $*.eps to $*.ppm ..."
	$(PSTOGIF) $*.eps
	-rm -f $*.gif
	-chmod $(DATAMODE) $*.ppm
	-rm -f $(DATAMODE) $*.ppm.tmp

.ppm.jpg:
	@$(ECHO) "Converting $*.ppm to $*.jpg ..."
	$(PPMTOJPEG) $*.ppm > $*.jpg
	-chmod $(DATAMODE) $*.gif

.eps.txt:
	@$(ECHO) "Converting $*.eps to $*.txt ..."
	@$(ECHO) ""                      > $*.txt
	@$(ECHO) "[Image file: $*.eps]" >> $*.txt
	-chmod $(DATAMODE) $*.txt

#----------------------------------------------------------------------------
# INSTALLATION: first, install manuals; then, install index entries.
install: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Installing manuals for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	$(MAKE) $(filter-out %index, \
              $(patsubst %,install%,$(DOCFORMATS)))
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Installing indices for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	$(MAKE) $(filter %index, \
	      $(patsubst %,install%,$(DOCFORMATS)))
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Done."
	@$(ECHO) "*** --------------------------------------------------------"

#----------------------------------------------------------------------------
# Installation of manuals (and deinstallation code)

installdvi: $(BASEMAIN).dvi 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Installing .dvi file for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-mkdir -p $(DOCDIR)
	-chmod $(EXECMODE) $(DOCDIR)
	-cp $(BASEMAIN).dvi $(DOCDIR) 
	-cp $(BASEMAIN)*.eps $(DOCDIR) 
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN).dvi
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN)*.eps
ifdef COMPRESSDVIPS
	$(COMPRESSDVIPS) $(DOCDIR)/$(BASEMAIN).dvi
	-$(ECHO) "<UL><LI><A HREF=$(BASEMAIN).dvi.gz>\
              <B>$(BASEMAIN)</B> Reference Manual - dvi,gzipped</A></UL>" \
              > $(DOCDIR)/$(BASEMAIN)_dvi.htmlindex
else
	-$(ECHO) "<UL><LI><A HREF=$(BASEMAIN).dvi>\
              <B>$(BASEMAIN)</B> Reference Manual - dvi</A></UL>" \
              > $(DOCDIR)/$(BASEMAIN)_dvi.htmlindex
endif
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN)_dvi.htmlindex
	-cp $(BASEMAIN)*.eps $(DOCDIR)
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN)*.eps

uninstalldvi: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Uninstalling .dvi file for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-rm -f $(DOCDIR)/$(BASEMAIN).dvi*
	-rm -f $(DOCDIR)/$(BASEMAIN)*.eps
	-rm -f $(DOCDIR)/$(BASEMAIN)_dvi.htmlindex
	-rm -f $(DOCDIR)/$(BASEMAIN)*.eps

installps: $(BASEMAIN).ps
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Installing .ps file for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-mkdir -p $(DOCDIR)
	-chmod $(EXECMODE) $(DOCDIR)
	-cp $(BASEMAIN).ps $(DOCDIR) 
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN).ps
ifdef COMPRESSDVIPS
	$(COMPRESSDVIPS) $(DOCDIR)/$(BASEMAIN).ps
	-$(ECHO) "<UL><LI><A HREF=$(BASEMAIN).ps.gz>\
              <B>$(BASEMAIN)</B> Reference Manual - postscript,gzipped</A></UL>" \
              > $(DOCDIR)/$(BASEMAIN)_ps.htmlindex
else
	-$(ECHO) "<UL><LI><A HREF=$(BASEMAIN).ps>\
              <B>$(BASEMAIN)</B> Reference Manual - postscript</A></UL>" \
              > $(DOCDIR)/$(BASEMAIN)_ps.htmlindex
endif
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN)_ps.htmlindex

uninstallps: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Uninstalling .ps for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-rm -f $(DOCDIR)/$(BASEMAIN).ps*
	-rm -f $(DOCDIR)/$(BASEMAIN)_ps.htmlindex

installhtml: $(BASEMAIN).html
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Installing .html file(s) for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-mkdir -p $(DOCDIR)/$(BASEMAIN)
	-chmod $(EXECMODE) $(DOCDIR)/$(BASEMAIN)
	-cp $(BASEMAIN)*.html $(DOCDIR)/$(BASEMAIN)
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN)/$(BASEMAIN)*.html
	-$(ECHO) "<UL><LI><A HREF=$(BASEMAIN)/$(BASEMAIN).html> \
              <B>$(BASEMAIN)</B> Reference Manual - html</A></UL>" \
              > $(DOCDIR)/$(BASEMAIN)_html.htmlindex
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN)_html.htmlindex
	-cp $(BASEMAIN)*.jpg $(DOCDIR)/$(BASEMAIN)
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN)/$(BASEMAIN)*.jpg

uninstallhtml: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Uninstalling .html file(s) for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-rm -f $(DOCDIR)/$(BASEMAIN)/$(BASEMAIN)*.html
	-rm -f $(DOCDIR)/$(BASEMAIN)/$(BASEMAIN)*.jpg
	-rm -f $(DOCDIR)/$(BASEMAIN)_html.htmlindex
	-rmdir $(DOCDIR)/$(BASEMAIN)

installinfo: $(BASEMAIN).info 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Installing .info file(s) for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-mkdir -p $(DOCDIR)
	-chmod $(EXECMODE) $(DOCDIR)
	-cp $(BASEMAIN).info* $(DOCDIR) 
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN).info*
	-$(ECHO) "<UL><LI> \
              <A HREF=$(BASEMAIN).info> \
              <B>$(BASEMAIN)</B> Reference Manual - gnu info</A></UL>" \
              > $(DOCDIR)/$(BASEMAIN)_info.htmlindex
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN)_info.htmlindex
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Remember to add entry to info dir (or select infoindex)!"
	@$(ECHO) "*** Remember to add $(DOCDIR) to INFOPATH!"
	@$(ECHO) "*** --------------------------------------------------------"

uninstallinfo: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Uninstalling .info file(s) for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-rm -f $(DOCDIR)/$(BASEMAIN).info*
	-rm -f $(DOCDIR)/$(BASEMAIN)_info.htmlindex

installascii: $(BASEMAIN).ascii
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Installing .ascii file(s) for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-mkdir -p $(DOCDIR)
	-chmod $(EXECMODE) $(DOCDIR)
	-cp $(BASEMAIN).ascii $(DOCDIR)
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN).ascii
	-$(ECHO) "<UL><LI> \
              <A HREF=$(BASEMAIN).ascii> \
              <B>$(BASEMAIN)</B> Reference Manual - ascii txt</A></UL>" \
              > $(DOCDIR)/$(BASEMAIN)_txt.htmlindex
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN)_txt.htmlindex

uninstallascii: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Uninstalling .ascii file(s) for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-rm -f $(DOCDIR)/$(BASEMAIN).ascii*
	-rm -f $(DOCDIR)/$(BASEMAIN)_txt.htmlindex

installmanl: $(BASEMAIN).manl
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Installing .manl as .l for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-mkdir -p $(DOCDIR)/manl
	-chmod $(EXECMODE) $(DOCDIR)/manl
	-cp $(BASEMAIN).manl $(DOCDIR)/manl/$(BASEMAIN).l
	-chmod $(DATAMODE) $(DOCDIR)/manl/$(BASEMAIN).l
	-$(ECHO) "<UL><LI> \
              <A HREF=manl/$(BASEMAIN).l> \
              <B>$(BASEMAIN)</B> Unix man entry (source)</A></UL>" \
              > $(DOCDIR)/$(BASEMAIN)_man.htmlindex
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN)_man.htmlindex
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Remember to add $(DOCDIR) to MANPATH!"
	@$(ECHO) "*** --------------------------------------------------------"

uninstallmanl: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Uninstalling .l file for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-rm -f $(DOCDIR)/manl/$(BASEMAIN).l
	-rm -f $(DOCDIR)/$(BASEMAIN)_man.htmlindex

#----------------------------------------------------------------------------
# Installation of index entries

installhtmlindex: $(BASEMAIN).htmlindex
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Installing html index for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-cp $(BASEMAIN).htmlbullet $(DOCDIR)
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN).htmlbullet
	-cp $(BASEMAIN).htmlindex $(DOCDIR) 
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN).htmlindex
	-chmod $(DATAMODE) $(DOCDIR)/*.html
	cat $(HTMLINDEXHEADFILE) > $(DOCDIR)/index.html 
	-cd $(DOCDIR); cat *.htmlbullet >> index.html 
	-cd $(DOCDIR); cat *.htmlindex >> index.html
	$(ECHO) "<p><hr><p><b>Last modified on:</b> `date`.<p>" \
                      >> $(DOCDIR)/index.html
	cat $(HTMLINDEXTAILFILE) >> $(DOCDIR)/index.html
	-chmod $(DATAMODE) $(DOCDIR)/index.html
	@$(ECHO) "*** WARNING: Files automatically generated -- do not edit!" \
	      > $(DOCDIR)/README
	-chmod $(DATAMODE) $(DOCDIR)/README
	-cp $(BASEMAIN)*.jpg $(DOCDIR)
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN)*.jpg

uninstallhtmlindex: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Uninstalling html index for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-rm -f $(DOCDIR)/$(BASEMAIN).htmlbullet
	-rm -f $(DOCDIR)/$(BASEMAIN).htmlindex
	cat $(HTMLINDEXHEADFILE) > $(DOCDIR)/index.html 
	-cd $(DOCDIR); cat *.htmlbullet  >> index.html 
	-cd $(DOCDIR); cat *.htmlindex >> index.html
	$(ECHO) "<p><hr><p><b>Last modified on</b> `date`<p>" \
                      >> $(DOCDIR)/index.html
	cat $(HTMLINDEXTAILFILE) >> $(DOCDIR)/index.html
	-cp $(BASEMAIN)*.jpg $(DOCDIR)
	-rm -f $(DOCDIR)/$(BASEMAIN)*.jpg

installinfoindex: $(BASEMAIN).infoindex
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Installing info index for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-mkdir -p $(DOCDIR)
	-chmod $(EXECMODE) $(DOCDIR)
	-cp $(BASEMAIN).infoindex $(DOCDIR) 
	-chmod $(DATAMODE) $(DOCDIR)/*.info
	-chmod $(DATAMODE) $(DOCDIR)/$(BASEMAIN).infoindex
	-cp $(INFODIRHEADFILE) $(INFODIRTAILFILE) $(DOCDIR) 
	cat $(INFODIRHEADFILE) > $(DOCDIR)/dir 
	-cd $(DOCDIR); cat *.infoindex >> dir
	cat $(INFODIRTAILFILE) >> $(DOCDIR)/dir
	-chmod $(DATAMODE) $(DOCDIR)/dir
	@$(ECHO) "*** WARNING: Files automatically generated -- do not edit!" \
	      > $(DOCDIR)/README
	-chmod $(DATAMODE) $(DOCDIR)/README

uninstallinfoindex: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Uninstalling info index for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-rm -f $(DOCDIR)/$(BASEMAIN).infoindex
	cat $(INFODIRHEADFILE) > $(DOCDIR)/dir 
	-cd $(DOCDIR); cat *.infoindex >> dir
	cat $(INFODIRTAILFILE) >> $(DOCDIR)/dir

#----------------------------------------------------------------------------
# Cleanup

# Eliminates all files installed  (provided SETTINGS file has not changed)
uninstall: 
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Uninstalling manuals and indices for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	$(MAKE) $(patsubst %,uninstall%,$(DOCFORMATS))
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Done."
	@$(ECHO) "*** --------------------------------------------------------"

# Eliminates intermediate files
distclean clean:
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Removing doc-related tmp files for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-rm -f *.aux *.cp *.cps *.fn *.fns *.ky *.kys *.log *.tp *.tps
	-rm -f *.op *.ops *.pd *.pds *.pr *.prs *.ug *.ugs
	-rm -f *.co *.cos *.fu *.fus *.li *.lis
	-rm -f *.pg *.pgs *.ap *.aps *.mo *.mos
	-rm -f *.toc *.te *.tes *.vr *.vrs *.de *.des
	-rm -f *.ltxi 
	-rm -f *.bbl *.blg
	-rm -f $(BASEMAIN)refs.el
	-rm -f *~

# Eliminates the doc files also
realclean: clean
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Removing doc files for $(BASEMAIN) ..."
	@$(ECHO) "*** --------------------------------------------------------"
	-rm -f $(BASEMAIN)*.dvi 
	-rm -f $(BASEMAIN)*.ps
	-rm -f $(BASEMAIN)*.ascii
	-rm -f $(BASEMAIN)*.html
	-rm -f $(BASEMAIN)*.htmlindex
	-rm -f $(BASEMAIN)*.htmlbullet
	-rm -f $(BASEMAIN)*.htmlsumm
	-rm -f $(BASEMAIN)*.l $(BASEMAIN)*.manl
	-rm -f $(BASEMAIN)*.info*
	-rm -f $(BASEMAIN)*.ppm
	-rm -f $(BASEMAIN)*.jpg
	-rm -f $(BASEMAIN)*.gif
	-rm -f $(BASEMAIN)*.txt
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Note: '$(MAKE) braveclean' deletes also the .texi files"
	@$(ECHO) "*** --------------------------------------------------------"

# Eliminates the .texi doc (i.e., the source) files also
braveclean: realclean
	@$(ECHO) "*** --------------------------------------------------------"
	@$(ECHO) "*** Removing texinfo, refs, and eps files for $(BASEMAIN)..."
	@$(ECHO) "*** --------------------------------------------------------"
	-rm *.texi *.refs *.eps
#----------------------------------------------------------------------------
# Some handy viewers:
dviview: $(BASEMAIN).dvi
	xdvi -s 8 -expert -geometry 623x879-0-0 $(BASEMAIN).dvi &

psview: $(BASEMAIN).ps
	ghostview -magstep -1 -portrait -geometry +349+10 $(BASEMAIN).ps &
# END
#----------------------------------------------------------------------------
